import pytest

def get_user_info(user_id):
    users = {
       1001:"name=tynam;age=21",
    }
    return users.get(user_id, "The user ID does not exist.")

def login():
    print("\n登录成功")
    user_id = 1001
    return user_id

def logout():
    print("\n登出成功")

@pytest.fixture()
def manage_login():
    user_id = login()
    # 在yield之前的代码在测试用例执行前运行,yield之后的代码在测试用例执行后运行
    # yield user_id是将user_id返回出去
    yield user_id
    logout()

def test_get_user_info_1(manage_login):
    print("\ntest_get_user_info_1 测试")
    user_id = manage_login
    assert get_user_info(user_id) == "name=tynam;age=21"

def test_get_user_info_2(manage_login):
    print("\ntest_get_user_info_2 测试")
    user_id = 1002
    assert get_user_info(user_id) == "The user ID does not exist."

if __name__ == '__main__':
    pytest.main(["-q", "pytest_study/pytest_fixture_test.py"])
    # -q: 显示print输出内容






